package com.dingyuhang.util;

import com.dingyuhang.bean.TbLog;
import com.dingyuhang.service.TbLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

public class MyLogIntercepotr extends HandlerInterceptorAdapter {
    @Autowired
    TbLogService tbLogService;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

       //强制转为HandlerMethod
        HandlerMethod handlerMethod=    ( HandlerMethod)handler;

        MyAnn methodAnnotation = handlerMethod.getMethodAnnotation(MyAnn.class);//获取带注解的方法

     if(null!=methodAnnotation) {//表示该方法标记自定义注解
         String value = methodAnnotation.value();//获取带注解的方法的值
     //    if (null != value) {//获取增加的注解
             //long t1 = System.currentTimeMillis();
          //   System.out.println("时间：" + t1 + "执行添加了");
         //    TbLog tbLog = new TbLog(value, null, new Date());
        //     tbLogService.addLog(tbLog);
      //   }
     }
        return true;
    }
}
